$( function() {	
	 $('#employeeTT').datagrid({
		 pageList:[10]
	 	});
	 
	$('#newEmployees').bind('click', function() {
		$('#dlgemployee').dialog('open').dialog('setTitle', '新建客户');
		$('#fmemployee').form('clear');
	});

	$('#saveEmployee').bind('click', function() {
		$('#fmemployee').form('submit', {
			onSubmit : function() {
				return $(this).form('validate');
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.errorMsg) {
					$.messager.show( {
						title :'Error',
						msg :result.errorMsg
					});
				} else {
					$('#dlgemployee').dialog('close'); // close the dialog
					$('#employeeTT').datagrid('reload'); // reload the user
			// data
		}
	}
		});
	});

	$('#modifyEmployee').bind('click', function() {
		$('#modifyEmployeeFM').form('submit', {
			onSubmit : function() {
				if ($('#new_pass').val() != $('#cofirme_pass').val()) {
					$.messager.show( {
						title :'错误',
						msg :"二次填写密码不一致"
					});
					return false;
				} else {
					return $(this).form('validate');
				}
			},
			success : function(result) {
				var result = eval('(' + result + ')');
				if (result.errorMsg) {
					$.messager.show( {
						title :'错误',
						msg :result.errorMsg
					});
				} else {
					$.messager.show( {
						title :'成功',
						msg :"修改成功"
					});
				}
			}
		});

	});
	//冻结
	$('#freezeEmploye').bind(
			'click',
			function() {
				var row = $('#employeeTT').datagrid('getSelected');
				if (row) {
					$.getJSON("employee/freeze/" + row.e_sn + ".html",
							function(result) {
						 		$.each( result, function( key, val ) {
									if(val.errorMsg){
										$.messager.show( {
											title :'错误',
											msg :result.errorMsg
										});
									} else {
										$.messager.show( {
											title :'成功',
											msg :'修改成功'
										});				
										$('#employeeTT').datagrid('reload'); // reload the user						
									}
									
							 	});
							});
				}
			});
	
	//激活
	$('#activateEmploye').bind(
			'click',
			function() {
				var row = $('#employeeTT').datagrid('getSelected');
				if (row) {
					$.getJSON("employee/activate/" + row.e_sn + ".html",
							function(result) {
						 		$.each( result, function( key, val ) {
									if(val && val.errorMsg){
										$.messager.show( {
											title :'错误',
											msg :result.errorMsg
										});
									} else {
										$.messager.show( {
											title :'成功',
											msg :'修改成功'
										});				
										$('#employeeTT').datagrid('reload'); // reload the user						
									}
									
							 	});
							});
				}
			});
	
	$('#viewPhotoEmploye').bind('click',function(){
		var row = $('#employeeTT').datagrid('getSelected');
		if (row) {
			$('#photo').attr('src','/${pageContext.request.contextPath}/fileupload/'+row.e_photo);
			$('#dlgphoto').dialog('open');
		}
	});
		
	 $("#searchEmployee").click(function(){
		   $('#employeeTT').datagrid('load',{  
			   e_sn: $('#e_sn').val(),
			   e_name:$('#e_name').val()
		    });  
	});
	 
	//打卡
	$("#daka").click(function(){
		var success = true;
		$.getJSON("WorkSchedule/addWS.html",
				function(result) {
			 		$.each( result, function( key, val ) {
						if(val){
							$.messager.show( {
								title :'错误',
								msg :result.errorMsg
							});
							success = false;
						}
						
				 	});
			 		if (success) {
			 			$.messager.show( {
							title :'成功',
							msg :'打卡成功'
						});	
			 		}
				});
		
	});
})